package com.xingfly.controller;

import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.lq.user.Users;
import com.xingfly.constant.AttributeConstant;
import com.xingfly.model.dto.User;

import com.xingfly.service.UserService;
import com.xingfly.util.StringUtil;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

/**
 * 	主界面控制器
 * @author 心之所向-LQ
 * Created by SuperS on 2019/5/22  23:20
 */
@SuppressWarnings("all")
@Controller
public class HomeController {
    @Resource
	private UserService userService;
    //启用日志对象
    private Logger log=Logger.getLogger(HomeController.class);
    /**
     *	查询所有的用户
     * @param 
     * @param 
     * @return
     */
    @RequestMapping(value="getAllUsers",produces="text/html;charset=utf-8")
    @ResponseBody
    public String SelByAll() {
    List<User> selByAll = userService.SelByAll();//单个查询根据偏好查询
    List<User>SleByALLO=userService.SelBycond(0);//查询所有的乘客
    Map<String,Object>map=new HashMap<String, Object>();
    map.put("code",0);
    map.put("msg","");
    map.put("data",selByAll);
    String result=JSONArray.toJSONString(map);
        return result;
    }
   
    /**
     *得到所有的标记为0的乘客
     * @return 鍏ㄩ儴 getAllUserServlet
     */
    @RequestMapping(value = "getAllUserServlet",produces ="application/json;charset=utf-8")
    @ResponseBody
    public String SelBycond() {
    	   List<User> selBycond = userService.SelBycond(0);
    	   Map<String,Object>map=new HashMap<String, Object>();
    	   try {
        	   map.put("data",selBycond);
    		   map.put("code",0);
    		   map.put("msg",AttributeConstant.succeed);
		   } catch (Exception e) {
			   e.printStackTrace();
			   log.warn("出现了一个错误"+e);
		   }
    	  String result=JSONArray.toJSONString(map);
    	  return result;
    }
}